﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;



public partial class Consultas_ConsultaSeguimientoTickets : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DateTime year = DateTime.Now;

            DateTime yearFinal = year.AddYears(5);
            DateTime yearInicial = year.AddYears(-5);
            DropDownListTextFiller.FillDropDownList(ddlDiaInicio, 1, 31,year.Day);
            DropDownListTextFiller.FillDropDownList(ddlMesInicio, 1, 12,year.Month);
            DropDownListTextFiller.FillDropDownList(ddlAnhoInicio,  yearInicial.Year, yearFinal.Year,year.Year);
        }
    }
    protected void btnConsultar_Click(object sender, EventArgs e)
    {
        SelectSentenceBuilder d = new SelectSentenceBuilder("vw_SeguimientoTicket");
        FilterDataBinder filterdatabinder = new FilterDataBinder();
        filterdatabinder.AddFilterData("orden", txtNumeroTicket, WhereFilter.WhereOperation.Equal, WhereFilter.SQLValueType.Integer);
        filterdatabinder.AddFilterData("id_oficina", ddlOficina, WhereFilter.WhereOperation.Equal, WhereFilter.SQLValueType.Integer);
        filterdatabinder.AddFilterData("id_tipo_ticket", ddlCodigoImpresion, WhereFilter.WhereOperation.Equal, WhereFilter.SQLValueType.Integer);
        filterdatabinder.AddFilterData("Fecha", new DropDownList[] { ddlDiaInicio, ddlMesInicio, ddlAnhoInicio }, WhereFilter.WhereOperation.Equal, WhereFilter.SQLValueType.String);
        filterdatabinder.BindData();

        DateTime? fecha= FilterDataBinder.GetDateFromDownDropLists(ddlDiaInicio, ddlMesInicio, ddlAnhoInicio);
        if (fecha.HasValue)  Session["Fecha"] = fecha.Value.ToShortDateString();

        d.Filters = filterdatabinder.Filters;
        d.Build();
        string selectstring = d.GetBuiltSelect();
        Session["SelectCommand"] = selectstring;
        Response.Redirect("RSeguimientoTickets.aspx");
    }
    protected override void OnError(EventArgs e)
    {

        HttpContext ctx = HttpContext.Current;

        Exception exception = ctx.Server.GetLastError();
        string errorInfo;
        if (exception is DateException)
            errorInfo = "<table align=\"center\"><tr><td><br><span style=\"color:red\">Se ingresó una o más fechas inválidas</span></br></td></tr></table>";
        else
            errorInfo =
                "<br>Offending URL: " + ctx.Request.Url.ToString() +
                "<br>Source: " + exception.Source +
                "<br>Message: " + exception.Message +
                "<br>Stack trace: " + exception.StackTrace;

        ctx.Response.Write(errorInfo);


        ctx.Server.ClearError();

        base.OnError(e);
    }
}
